package cn.tedu.mybatisannotation.mapper;

import cn.tedu.mybatisannotation.pojo.UserVO;
import cn.tedu.mybatisannotation.pojo.Weibo;
import cn.tedu.mybatisannotation.pojo.WeiboVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

//1.添加@Mapper注解
@Mapper
public interface WeiboMapper {

    @Insert("INSERT INTO weibo VALUES(NULL,#{content},#{created},#{userId})")
    int insert(Weibo weibo);

    @Delete("DELETE FROM weibo WHERE id=#{id}")
    int deleteById(int id);

    /**修改数据*/
    @Update("UPDATE weibo SET content=#{content},created=#{created},user_id=#{userId} WHERE id=#{id}")
    int updateById(Weibo weibo);

    /**查询表中所有数据*/
    @Select("SELECT * FROM weibo")
    List<Weibo> selectAll();

    /**根据id查询数据*/
    @Select("SELECT * FROM weibo WHERE id=#{id}")
    Weibo selectById(int id);

    /**查询指定字段数据*/
    @Select("SELECT content,created,user_id userId FROM weibo")
    List<WeiboVO> selectByCol();

    /**查询id小于5的用户名和密码*/
    @Select("SELECT username,password FROM user WHERE id<#{id}")
    List<UserVO> selectUser(int id);
}










